﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ArrayLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            //StringBuilder[] builders = new StringBuilder[5];
            //builders[0] = new StringBuilder("builder1");
            //builders[1] = new StringBuilder("builder2");
            //builders[2] = new StringBuilder("builder3");
            //StringBuilder[] builders2 = builders;
            //StringBuilder[] shallowClone = (StringBuilder[])builders.Clone();
            //for (int i = 0; i < shallowClone.Length;i++ )
            //    Console.WriteLine(shallowClone[i]);
            //Console.ReadLine();

            //CreateArray();
            //DynamicCreateArray();

            //EnumerationForeach();
            //EnumerationForEach();
            LengthAndRank();
        }

        private static void CreateArray()
        {
            //第一种方式用来创建数组
            int[] myArrays = { 1, 2, 3 };
            int first = myArrays[0];
            myArrays.SetValue(100, 0);
            first = myArrays[0];
            Console.WriteLine("第一个元素" + first.ToString());
            Console.ReadLine();

        }

        private static void DynamicCreateArray()
        {
            //定义一个三个元素的string数组
            Array a = Array.CreateInstance(typeof(string), 3);
            a.SetValue("Hello", 0);
            a.SetValue("World", 1);
            a.SetValue("MyDear", 2);

            string s = (string)a.GetValue(0);
            Console.WriteLine("第零个元素" + s);
            Console.ReadLine();
        }

        private static void EnumerationForeach()
        {
            int[] myArrays = { 1, 2, 3, 4, 5 };
            foreach (int value in myArrays)
            {
                Console.WriteLine("数值是" + value);
            }
            Console.ReadLine();
        }

        private static void EnumerationForEach()
        {
            Array.ForEach(new[] { 1, 2, 3 }, Console.WriteLine);
            Console.ReadLine();
        }


        private static void LengthAndRank()
        {
            int[] datas = { 1, 2, 3, 4, 5 };
            int a = datas.GetLength(0);
            Console.WriteLine(a);
        }
    }
}
